<!--
版权所有 © 2025 [noora]
此代码基于工程计算公式原创开发，允许自由使用
-->

<!DOCTYPE html>
<html lang="zh-CN">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no">
    <title>卷重计算器</title>
    <style>
        :root {
            --primary-color: #3498db;
            --secondary-color: #2980b9;
            --success-color: #2ecc71;
            --error-color: #e74c3c;
            --text-color: #333;
            --light-text: #7f8c8d;
            --bg-color: #f5f5f5;
            --card-bg: #ffffff;
        }

        * {
            box-sizing: border-box;
        }

        body {
            font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
            margin: 0;
            padding: 10px;
            background-color: var(--bg-color);
            color: var(--text-color);
            line-height: 1.5;
            -webkit-text-size-adjust: 100%;
        }

        .container {
            max-width: 800px;
            margin: 0 auto;
            background-color: var(--card-bg);
            border-radius: 12px;
            padding: 20px;
            box-shadow: 0 2px 10px rgba(0, 0, 0, 0.1);
        }

        h1 {
            color: var(--primary-color);
            text-align: center;
            margin: 15px 0 25px;
            font-size: 1.8rem;
        }

        .method-card {
            background-color: var(--card-bg);
            padding: 20px;
            border-radius: 10px;
            margin-bottom: 20px;
            cursor: pointer;
            transition: all 0.3s ease;
            border: 1px solid #e0e0e0;
            box-shadow: 0 2px 5px rgba(0, 0, 0, 0.05);
        }

        .method-card:hover,
        .method-card:active {
            transform: translateY(-3px);
            box-shadow: 0 5px 15px rgba(0, 0, 0, 0.1);
            border-color: var(--primary-color);
        }

        .method-card h2 {
            color: var(--primary-color);
            margin: 0 0 10px;
            font-size: 1.3rem;
        }

        .method-card p {
            color: var(--light-text);
            margin: 0;
            font-size: 0.95rem;
        }

        .calculator {
            display: none;
            animation: fadeIn 0.3s ease;
        }

        @keyframes fadeIn {
            from {
                opacity: 0;
                transform: translateY(10px);
            }

            to {
                opacity: 1;
                transform: translateY(0);
            }
        }

        .back-btn {
            display: inline-flex;
            align-items: center;
            background-color: #f0f0f0;
            color: #555;
            border: none;
            padding: 10px 15px;
            border-radius: 6px;
            cursor: pointer;
            margin-bottom: 20px;
            font-size: 0.95rem;
            transition: all 0.2s;
        }

        .back-btn:hover,
        .back-btn:active {
            background-color: #e0e0e0;
        }

        .input-group {
            margin-bottom: 18px;
        }

        label {
            display: block;
            margin-bottom: 8px;
            font-weight: 600;
            color: var(--text-color);
            font-size: 0.95rem;
        }

        input,
        select {
            width: 100%;
            padding: 12px 15px;
            border: 1px solid #ddd;
            border-radius: 8px;
            font-size: 1rem;
            transition: all 0.3s;
            -webkit-appearance: none;
        }

        input:focus,
        select:focus {
            border-color: var(--primary-color);
            outline: none;
            box-shadow: 0 0 0 3px rgba(52, 152, 219, 0.1);
        }

        button {
            background-color: var(--primary-color);
            color: white;
            border: none;
            padding: 15px;
            width: 100%;
            border-radius: 8px;
            cursor: pointer;
            font-size: 1.1rem;
            font-weight: 600;
            margin-top: 10px;
            transition: all 0.3s;
        }

        button:hover,
        button:active {
            background-color: var(--secondary-color);
        }

        .result {
            margin-top: 25px;
            padding: 18px;
            background-color: rgba(46, 204, 113, 0.1);
            border-radius: 8px;
            display: none;
            border-left: 4px solid var(--success-color);
        }

        .result h3 {
            color: var(--success-color);
            margin: 0 0 10px;
            font-size: 1.1rem;
        }

        .result p {
            margin: 8px 0;
            font-size: 1rem;
        }

        .error {
            color: var(--error-color);
            margin: 15px 0;
            padding: 12px;
            background-color: rgba(231, 76, 60, 0.1);
            border-radius: 6px;
            display: none;
            font-size: 0.95rem;
        }

        .highlight {
            color: var(--primary-color);
            font-weight: bold;
            font-size: 1.2rem;
        }

        .unit {
            color: var(--light-text);
            font-size: 0.85rem;
            margin-left: 5px;
            font-weight: normal;
        }

        /* 移动端特定样式 */
        @media (max-width: 600px) {
            .container {
                padding: 15px;
                border-radius: 0;
            }

            h1 {
                font-size: 1.5rem;
                margin: 10px 0 20px;
            }

            .method-card {
                padding: 15px;
                margin-bottom: 15px;
            }

            .method-card h2 {
                font-size: 1.2rem;
            }

            input,
            select {
                padding: 14px 15px;
                font-size: 1.05rem;
            }

            button {
                padding: 16px;
            }

            .result {
                padding: 15px;
            }
        }

        /* 防止iOS缩放 */
        @media screen and (max-width: 600px) {

            input,
            select,
            textarea {
                font-size: 16px !important;
            }
        }
    </style>
</head>

<body>
    <div class="container">
        <!-- 主页面 -->
        <div id="main-page">
            <h1>卷重计算器</h1>

            <div class="method-card" onclick="showCalculator('thickness')">
                <h2>壁厚计算法</h2>
                <p>已知内径、壁厚、宽度计算卷重</p>
            </div>

            <div class="method-card" onclick="showCalculator('length')">
                <h2>长度计算法</h2>
                <p>已知宽度、厚度、长度和铝卷条数计算重量</p>
            </div>
        </div>

        <!-- 壁厚计算法 -->
        <div id="thickness-calculator" class="calculator">
            <button class="back-btn" onclick="backToMain()">← 返回主页面</button>
            <h2>壁厚计算法</h2>

            <div class="input-group">
                <label for="innerDiameter">内径 <span class="unit">(mm)</span></label>
                <input type="number" id="innerDiameter" step="0.01" placeholder="例如: 500" inputmode="decimal">
            </div>
            <div class="input-group">
                <label for="thickness">壁厚 <span class="unit">(mm)</span></label>
                <input type="number" id="thickness" step="0.01" placeholder="例如: 500" inputmode="decimal">
            </div>
            <div class="input-group">
                <label for="width1">宽度 <span class="unit">(mm)</span></label>
                <input type="number" id="width1" step="0.01" placeholder="例如: 1000" inputmode="decimal">
            </div>
            <div class="input-group">
                <label for="density1">密度 <span class="unit">(g/cm³)</span></label>
                <input type="number" id="density1" step="0.01" value="2.7" inputmode="decimal">
            </div>
            <button onclick="calculateThickness()">计算重量</button>
            <div id="error1" class="error"></div>
            <div id="result1" class="result">
                <h3>计算结果</h3>
                <p>铝卷重量: <span id="weight1" class="highlight">0</span> kg</p>
            </div>
        </div>

        <!-- 长度计算法 -->
        <div id="length-calculator" class="calculator">
            <button class="back-btn" onclick="backToMain()">← 返回主页面</button>
            <h2>长度计算法</h2>

            <div class="input-group">
                <label for="thickness2">厚度 <span class="unit">(mm)</span></label>
                <input type="number" id="thickness2" step="0.01" placeholder="例如: 2" inputmode="decimal">
            </div>

            <div class="input-group">
                <label for="width2">宽度 <span class="unit">(mm)</span></label>
                <input type="number" id="width2" step="0.01" placeholder="例如: 300" inputmode="decimal">
            </div>

            <div class="input-group">
                <label for="length">长度 <span class="unit">(m)</span></label>
                <input type="number" id="length" step="0.01" placeholder="例如: 1000" inputmode="decimal">
            </div>
            <div class="input-group">
                <label for="quantity">铝卷条数</label>
                <input type="number" id="quantity" step="1" value="1" min="1" inputmode="numeric">
            </div>
            <div class="input-group">
                <label for="density2">密度 <span class="unit">(g/cm³)</span></label>
                <input type="number" id="density2" step="0.01" value="2.7" inputmode="decimal">
            </div>
            <button onclick="calculateLength()">计算总重量</button>
            <div id="error2" class="error"></div>
            <div id="result2" class="result">
                <h3>计算结果</h3>
                <p>单条重量: <span id="singleWeight">0</span> kg</p>
                <p>总重量: <span id="totalWeight" class="highlight">0</span> kg <span class="unit">(共 <span
                            id="totalQuantity">1</span> 条)</span></p>
            </div>
        </div>
    </div>

    <script>
        // 显示主页面
        function backToMain() {
            document.getElementById('main-page').style.display = 'block';
            document.getElementById('thickness-calculator').style.display = 'none';
            document.getElementById('length-calculator').style.display = 'none';

            // 清空结果和错误
            document.getElementById('result1').style.display = 'none';
            document.getElementById('result2').style.display = 'none';
            document.getElementById('error1').style.display = 'none';
            document.getElementById('error2').style.display = 'none';
        }

        // 显示对应计算器
        function showCalculator(type) {
            document.getElementById('main-page').style.display = 'none';
            if (type === 'thickness') {
                document.getElementById('thickness-calculator').style.display = 'block';
            } else {
                document.getElementById('length-calculator').style.display = 'block';
            }
        }

        // 壁厚计算法
        function calculateThickness() {
            const innerDiameter = parseFloat(document.getElementById('innerDiameter').value);
            const thickness = parseFloat(document.getElementById('thickness').value);
            const width = parseFloat(document.getElementById('width1').value);
            const density = parseFloat(document.getElementById('density1').value) || 2.7;

            // 验证输入
            const errorElement = document.getElementById('error1');
            errorElement.textContent = '';
            errorElement.style.display = 'none';

            if (isNaN(innerDiameter) || isNaN(thickness) || isNaN(width)) {
                errorElement.textContent = '请输入有效的数值！';
                errorElement.style.display = 'block';
                return;
            }
            if (thickness <= 0 || width <= 0 || innerDiameter < 0) {
                errorElement.textContent = '壁厚、宽度必须大于0，内径不能为负！';
                errorElement.style.display = 'block';
                return;
            }

            // 计算公式：π × (内径 + 壁厚) × 壁厚 × 宽度 × 密度 × 10^-6
            const meanDiameter = innerDiameter + thickness;
            const weightKg = Math.PI * meanDiameter * thickness * width * density * 1e-6;

            // 显示结果
            document.getElementById('weight1').textContent = weightKg.toFixed(2);
            document.getElementById('result1').style.display = 'block';

            // 自动滚动到结果
            document.getElementById('result1').scrollIntoView({ behavior: 'smooth', block: 'nearest' });
        }

        // 长度计算法
        function calculateLength() {
            const thickness = parseFloat(document.getElementById('thickness2').value);
            const width = parseFloat(document.getElementById('width2').value);
            const length = parseFloat(document.getElementById('length').value);
            const quantity = parseInt(document.getElementById('quantity').value) || 1;
            const density = parseFloat(document.getElementById('density2').value) || 2.7;

            // 验证输入
            const errorElement = document.getElementById('error2');
            errorElement.textContent = '';
            errorElement.style.display = 'none';

            if (isNaN(width) || isNaN(thickness) || isNaN(length) || isNaN(quantity)) {
                errorElement.textContent = '请输入有效的数值！';
                errorElement.style.display = 'block';
                return;
            }
            if (width <= 0 || thickness <= 0 || length <= 0 || quantity <= 0) {
                errorElement.textContent = '所有数值必须大于0！';
                errorElement.style.display = 'block';
                return;
            }

            // 单位转换：长度米→毫米
            const lengthMm = length * 1000;

            // 计算公式：厚度 × 宽度 × 长度 × 密度 × 10^-6
            const singleWeight = thickness * width * lengthMm * density * 1e-6;
            const totalWeight = singleWeight * quantity;

            // 显示结果
            document.getElementById('singleWeight').textContent = singleWeight.toFixed(2);
            document.getElementById('totalWeight').textContent = totalWeight.toFixed(2);
            document.getElementById('totalQuantity').textContent = quantity;
            document.getElementById('result2').style.display = 'block';

            // 自动滚动到结果
            document.getElementById('result2').scrollIntoView({ behavior: 'smooth', block: 'nearest' });
        }

        // 初始化显示主页面
        backToMain();
    </script>
</body>

</html>